package com.ruoyi.yljf.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.yljf.domain.Comment;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 评论管理Mapper接口
 * 
 * @author metaee
 * @date 2025-02-14
 */
public interface CommentMapper extends BaseMapper<Comment> {

    @Update("UPDATE yljf_comment SET likes = likes + 1 WHERE id = #{id}")
    void like(Long id );

    @Update("UPDATE yljf_comment SET likes = likes - 1 WHERE id = #{id}")
    void unLike(Long id);

    @Select("SELECT * FROM yljf_comment WHERE parent_id IN (\n" +
            "  SELECT id FROM yljf_comment WHERE user_id = #{userId} AND post_type != #{type} )"  )
    List<Comment> queryList(@Param("userId") Long userId, @Param("type") String type);

    @Select("SELECT * FROM yljf_comment WHERE parent_id IN (\n" +
            "  SELECT id FROM yljf_comment WHERE user_id = #{userId} AND post_type = #{type} )"  )
    List<Comment> selectQuestionCount(@Param("userId") Long userId, @Param("type") String type);
}
